﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows.Controls;
using CoiffeurProject.Screens;
using System.Windows;
using System.Windows.Media;
using System.Windows.Media.Imaging;

namespace CoiffeurProject.UserControls
{
    internal class FilterPanel
    {
        Grid main_container;
        List<ComboBox> comboBoxes;
        Button reset;

        internal FilterPanel(Thickness margin, int row, int column, List<List<String>> comboBoxesValue,
            List<Action<object, SelectionChangedEventArgs>> selectionChangedHandlers,
            Action<object, RoutedEventArgs> resetClickHandler)
        {

            #region Initialize Grid

            main_container = new Grid()
            {
                Width = 368,
                Height = 255,
                Margin = margin,
                VerticalAlignment = VerticalAlignment.Top,
                HorizontalAlignment = HorizontalAlignment.Left
            };

            Grid.SetColumn(main_container, column);
            Grid.SetRow(main_container, row);

            #endregion

            #region Load Combo Box

            comboBoxes = new List<ComboBox>(comboBoxesValue.Count);

            for (int i = 0; i < comboBoxesValue.Count; i++)
            {

                var combobox = new ComboBox()
                {
                    Width = 345,
                    Height = 40,
                    HorizontalAlignment = HorizontalAlignment.Left,
                    VerticalAlignment = VerticalAlignment.Top,
                    Margin = new Thickness(20, 45 + 50 * i, 0, 0),
                    SelectedIndex = 0,
                    HorizontalContentAlignment = HorizontalAlignment.Center,
                    VerticalContentAlignment = VerticalAlignment.Center,
                    Foreground = new SolidColorBrush(Colors.White),
                    FontFamily = new FontFamily("Segoe UI"),
                    FontSize = 20
                };

                ComboBoxItem[] items = new ComboBoxItem[comboBoxesValue[i].Count];

                for (int j = 0; j < comboBoxesValue[i].Count; j++)
                {
                    var item = new ComboBoxItem() { Content = comboBoxesValue[i][j] };

                    item.SetResourceReference(ComboBoxItem.StyleProperty,
                        "SimpleComboBoxItem");
                    items[j] = item;
                }

                combobox.ItemsSource = items;
                combobox.SelectedIndex = 0;
                combobox.SelectionChanged += new SelectionChangedEventHandler(selectionChangedHandlers[i]);

                main_container.Children.Add(combobox);

                comboBoxes.Add(combobox);
            }

            #endregion

            #region Load Reset Button

            reset = new Button()
            {
                Width = 57,
                Height = 14,
                Margin = new Thickness(300, 13, 0, 0),
                HorizontalAlignment = HorizontalAlignment.Left,
                VerticalAlignment = VerticalAlignment.Top,
                Content = new Image()
                {
                    Source = new BitmapImage(new Uri(
                        @"pack://application:,,,/CoiffeurProject;component/Images/Customer/Icons/reset.PNG")),
                    Stretch = Stretch.Fill
                }
            };

            reset.SetResourceReference(Button.StyleProperty, "NoChromeButton");

            reset.Click += new RoutedEventHandler(reset_Click);
            reset.Click += new RoutedEventHandler(resetClickHandler);

            main_container.Children.Add(reset);

            #endregion
        }

        void reset_Click(object sender, RoutedEventArgs e)
        {
            for (int i = 0; i < comboBoxes.Count; i++)
                comboBoxes[i].SelectedIndex = 0;
        }

        public Grid MainContainer
        {
            get { return main_container; }
        }

        public List<ComboBox> ComboBoxes
        {
            get { return comboBoxes; }
        }
    }

}
